import 'package:flutter/material.dart';

class InputWidget extends StatelessWidget {
  // const InputWidget({super.key});

  final String? placeHolder;
  final bool isPwd;

  // 文本框中内容变动事件
  final ValueChanged<String>? onChanged;
  // 文本框输入内容的类型
  // 例如在账号/密码文本框中只能输入
  // 字符数字和符号 - 不能输入中文
  final TextInputType? keyboardType;

  final FocusNode? focusNode;
  final ValueChanged<String>? onFieldSubmitted;

  // 构造方法，在花括号内的属性都是可选的
  // 可通过 required 标识为必填（也可以将属性前置到花括号外面，表示必填）
  // 也可以设置默认值
  const InputWidget({
    Key? key,
    required this.placeHolder,
    this.onChanged,
    this.isPwd = false,
    this.keyboardType, this.focusNode, this.onFieldSubmitted
  }):super(key:key);

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        _input(),
        const Divider(
          color: Colors.white, height: 1, thickness: 0.5,
        )
      ],
    );
  }

  _input() {
    return TextField(
      onChanged: onChanged, obscureText: isPwd, keyboardType: keyboardType, autofocus: !isPwd, cursorColor: Colors.white,
      focusNode: focusNode, onSubmitted: onFieldSubmitted,
      style: const TextStyle(// 文本样式
        fontSize: 17, color: Colors.white, fontWeight: FontWeight.w400,
      ),
      decoration: InputDecoration(// Input widget 样式
        border: InputBorder.none, hintText: placeHolder, hintStyle: const TextStyle(fontSize: 17, color: Colors.grey)
      ),
    );
  }
}
